package com.github.zxhTom.demo.jol;

public class Volatile {
    static volatile boolean flag = true;
    static int index=0;
    public static void main(String[] args) throws InterruptedException {
        new Thread(new Runnable() {
            public void run() {
                while (flag) {
                    index++;
                }
                System.out.println("flag被改了，我也要走了哦。。。。。。"+index);
            }
        },"hellone").start();
        Thread.sleep(1000);
        flag=false;
        System.out.println("我是主线程");
    }
}
